<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><!---
Kalendar Admin

COPYRIGHT & LICENSING INFO
-------------------------------------------------------------------

Copyright 2006 TJ Downes - tdownes@sanative.net - http://www.sanative.net

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

--->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<cfheader name="Expires" value="#Now()#" />
<title>Kalendar</title>
<cfparam name="appAction" default="displayCalendar" />
<cfparam name="form.IsFeatured" default="0" type="boolean" />
<cfparam name="form.IsPublished" default="0" type="boolean" />

<link href="<cfoutput>#application.KConfig.getKalendarURLPath()#</cfoutput>common/css/kalendar.css" rel="stylesheet" type="text/css" />
<link href="<cfoutput>#application.KConfig.getKalendarURLPath()#</cfoutput>admin/common/css/main.css" rel="stylesheet" type="text/css" />
<cfif NOT Compare(appAction, "addCategory") OR NOT Compare(appAction, "editCategory")>
<link href="categories.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
<!--
//<![CDATA[
	var theElement = "";
	
	function colorPicker_callBack(strColor) {
		document.getElementById(theElement).value = strColor;
		changeBGColor();
		changeTextColor();
	}
	
	function openColorPickerAdv() {
		document.getElementById('colorPickerAdvDiv').style.visibility = 'visible';
	}
	
	function handleFocus(e) {
		theElement = e;
	}
	
	function closeColorPickerAdv() {
		document.getElementById('colorPickerAdvDiv').style.visibility = 'hidden';
	}
	
	function changeBGColor() {
		if(document.getElementById('CategoryBGColor').value.length) {
			document.getElementById('colorswatch').style.backgroundColor = "#" + document.getElementById('CategoryBGColor').value;
		}
	}
	
	function changeTextColor() {
		if(document.getElementById('CategoryTextColor').value.length) {
			document.getElementById('colorswatch').style.color = "#" + document.getElementById('CategoryTextColor').value;
		}
	}
//]]>
//-->
</script>
<script type="text/javascript">
	//<![CDATA[
	function getCategory() {
		var CategoryID = document.getElementById('categoriesForm').CategoryIDSelector.options[document.getElementById('categoriesForm').CategoryIDSelector.selectedIndex].value;
		document.location.href="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>?appAction=editCategory&CategoryID=" + CategoryID;
	}
	<cfif NOT Compare(appAction, "editCategory")>
		
	function cancelEdit() {
		document.location.href="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>?appAction=addCategory";
	}
		
	function deleteCategory() {
		var CategoryID = document.getElementById('categoriesForm').CategoryID.value;
		var agree=confirm("This record will be deleted. Would you like to continue? IT CANNOT BE UNDONE!");
		if(agree) {
			document.location.href="<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>?appAction=deleteCategory&CategoryID=" + CategoryID;
		}
	}
	</cfif>//]]>
</script>
</cfif>
<cfif NOT Compare(appAction, "displayImportData")>
<script language="javascript" type="text/javascript">
	//<![CDATA[
	var lastState = false;
	function selectAll(val) {
		with(document.dataImportForm) {
			var d;
			d=document.getElementsByTagName("input");
			for(i=0;i<d.length;i++) {
				if(d[i].type=="checkbox") {
     				d[i].checked=val;
				}
			}
		}        
	}
    function toggleList() {
        lastState == false ? selectAll(true) : selectAll(false);
        lastState = lastState == true ? false: true;
    }
    //]]>
</script>
</cfif>
<cfif NOT Compare(appAction, "addRecord") OR NOT Compare(appAction, "editRecord")>
<!-- calendar stylesheet -->
<link rel="stylesheet" type="text/css" media="all" href="<cfoutput>#application.KConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar-win2k-cold-1.css" title="win2k-cold-1" />
<!-- main calendar program -->
<script type="text/javascript" src="<cfoutput>#application.KConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar.js"></script>
<!-- language for the calendar -->
<script type="text/javascript" src="<cfoutput>#application.KConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/lang/calendar-en.js"></script>
<!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
<script type="text/javascript" src="<cfoutput>#application.KConfig.getJavascriptPath()#</cfoutput>jscalendar-1.0/calendar-setup.js"></script>
<script type="text/javascript">
	//<![CDATA[
	function checkIt() {
		var oEditor = FCKeditorAPI.GetInstance('Description');
			oEditor.UpdateLinkedField();
		if(!document.eventForm.Description.value) {
			alert('Body is a required field');
			return false;
		}
		if(Date.parse(document.eventForm.StartDate.value) > Date.parse(document.eventForm.EndDate.value)) {
			alert('Start Date must be the same as or before the end date');
			return false;	
		}
	}
	//]]>
</script>
</cfif>
<cfif NOT Compare(appAction, "editRecord")>
<script type="text/javascript">
	//<![CDATA[
	function removeRecord() {
	var agree=confirm("This record will be deleted. Would you like to continue?")
		if (agree)
		window.location.href = "<cfoutput>#cgi.SCRIPT_NAME#</cfoutput>?appAction=deleteRecord&EventID=<cfoutput>#url.EventID#</cfoutput>";
	
	}
//]]>
</script>
</cfif>
</head>
<body<cfif NOT Compare(appAction, "addCategory") OR NOT Compare(appAction, "editCategory")> onload="changeBGColor();changeTextColor();"</cfif>
<div style="margin-top:12px; margin-left: auto; margin-right: auto; padding-left:25px; width:790px;">
	<a href="<cfoutput>#cgi.SCRIPT_NAME#?appAction=displayCalendar</cfoutput>">Edit</a> &middot; <a href="<cfoutput>#cgi.SCRIPT_NAME#?appAction=addRecord</cfoutput>">Add</a> &middot; <a href="<cfoutput>#cgi.SCRIPT_NAME#?appAction=addCategory</cfoutput>">Category Manager</a> &middot; <a href="<cfoutput>#cgi.SCRIPT_NAME#?appAction=displayImportForms</cfoutput>">import events</a> &middot; <a href="<cfoutput>#application.KConfig.getKalendarURLPath()#</cfoutput>">public view</a>
	<p />
	<div align="left" style="width:650px;">
	<cfswitch expression="#appAction#">
		
		<cfcase value="addRecord">
		<cfsilent>
		<cfscript>
			event = StructNew();
				event.EventID = CreateUUID();
				event.CategoryID = 0;
				event.IsFeatured = 0;
				event.IsPublished = 0;
				event.Title = "";
				event.StartDate = "";
				event.EndDate = "";
				event.StartTime = "";
				event.EndTime = "";
				event.Location = "";
				event.ExternalURL = "";
				event.ContactName = "";
				event.ContactEmail = "";
				event.ContactPhone = "";
				event.Teaser = "";
				event.Description = "";
		</cfscript>
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="getMultipleRecords"
					returnvariable="returnedCategories" />
		</cfsilent>
		<cfinclude template="display_form.cfm" />
		</cfcase>
		
		<cfcase value="editRecord">
		<cfsilent>
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="getMultipleRecords"
					returnvariable="returnedCategories" />
					
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendar"
					method="getSingleRecord"
					returnvariable="returnedEvent" EventID="#URL.EventID#" />
		<cfscript>
			event = StructNew();
				event.EventID = returnedEvent.EventID;
				event.CategoryID = returnedEvent.CategoryID;
				event.IsFeatured = returnedEvent.IsFeatured;
				event.IsPublished = returnedEvent.IsPublished;
				event.Title = returnedEvent.Title;
				event.StartDate = DateFormat(returnedEvent.StartDate, "m/d/yyyy");
				event.EndDate = DateFormat(returnedEvent.EndDate, "m/d/yyyy");
				event.StartTime = TimeFormat(returnedEvent.StartTime, "h:mm tt");
				event.EndTime = TimeFormat(returnedEvent.EndTime, "h:mm tt");
				event.Location = returnedEvent.Location;
				event.ExternalURL = returnedEvent.ExternalURL;
				event.ContactName = returnedEvent.ContactName;
				event.ContactEmail = returnedEvent.ContactEmail;
				event.ContactPhone = returnedEvent.ContactPhone;
				event.Teaser = returnedEvent.Teaser;
				event.Description = returnedEvent.Description;
		</cfscript>
		</cfsilent>
		<cfinclude template="display_form.cfm" />
		</cfcase>
		
		<cfcase value="displayCalendar">
		<cfsilent>
		<!--- default view to large month format. Acceptable types: month, week, list (mini calendar) --->
		<cfparam name="view" default="month" type="string" />
		<cfparam name="LinkDate" default="" />
		<cfparam name="categoryID" default="0" type="numeric" />
		
		<!--- ERROR PREVENTION: prevents errors by intentional munging of the URL --->
		<cfif StructKeyExists(url, "view")>
			<cfset variables.view = url.view />
		</cfif>
		<cfif StructKeyExists(form, "view")>
			<cfset variables.view = form.view />
		</cfif>
		
		<cfif NOT ListFindNoCase('day,weeklist,list,month,week,rss',variables.view)>
			<cfset view = "list" />
		</cfif>
		
		<cfif StructKeyExists(url, "linkDate")>
			<cfset variables.LinkDate = url.LinkDate />
		</cfif>
		<cfif StructKeyExists(form, "linkDate")>
			<cfset variables.LinkDate = form.LinkDate />
		</cfif>

		<cfif StructKeyExists(url, "categoryID")>
			<cfset variables.categoryID = url.categoryID />
		</cfif>
		<cfif StructKeyExists(form, "categoryID")>
			<cfset variables.categoryID = form.categoryID />
		</cfif>
		
		<!--- ERROR PREVENTION: prevents errors by intentional munging of the URL --->
		<cfif NOT ListFindNoCase('day,weeklist,month,week',view)>
			<cfset view = "list" />
		</cfif>
		
		<cfif NOT isDate(LinkDate)>
			<cfset LinkDate = DateFormat(Now(), 'mmmm d, yyyy') />
		</cfif>
		<!--- ERROR PREVENTION: End --->
		
		<!--- instantiate object for Kalendar data --->
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendar" method="getCalendar" returnvariable="returnedEvents">
			<cfif NOT Compare(variables.view,"list")>
				<cfinvokeargument name="view" value="month" />
			<cfelseif NOT Compare(variables.view,"weeklist")>
				<cfinvokeargument name="view" value="week" />
			<cfelse>
				<cfinvokeargument name="view" value="#variables.view#" />
			</cfif>
			<cfinvokeargument name="timeHeaderClass" value="timeHeader" />
			<cfinvokeargument name="LinkDate" value="#CreateODBCDate(variables.LinkDate)#" />
			<cfinvokeargument name="PublicOnly" value="0" />
			<cfinvokeargument name="PublicOnly" value="0" />
			<cfif variables.categoryID neq 0>
				<cfinvokeargument name="categoryID" value="#variables.categoryID#" />
			</cfif>
		</cfinvoke>
		</cfsilent>
		<cfinclude template="display_records.cfm" />
		</cfcase>
		
		<cfcase value="createRecord">
		<cfsilent>
		<cfif Len(Trim(form.NewCategoryName))>
			<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories" method="createRecord" returnvariable="returnedCreateCategory">
				<cfinvokeargument name="CategoryName" value="#form.NewCategoryName#" />
			</cfinvoke>
			<cfset form.CategoryID = returnedCreateCategory.NewCategoryID />
		</cfif>
		<cfif NOT Len(Trim(form.EndDate))>
			<cfset form.EndDate = form.StartDate />
		</cfif>
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendar" method="createRecord" returnvariable="returnMessage">
			<cfinvokeargument name="EventID" value="#form.EventID#" />
			<cfinvokeargument name="CategoryID" value="#form.CategoryID#" />
			<cfinvokeargument name="IsFeatured" value="#form.IsFeatured#" />
			<cfinvokeargument name="IsPublished" value="#form.IsPublished#" />
			<cfinvokeargument name="StartDate" value="#form.StartDate#" />
			<cfinvokeargument name="EndDate" value="#form.EndDate#" />
			<cfinvokeargument name="StartTime" value="#form.StartTime#" />
			<cfinvokeargument name="EndTime" value="#form.EndTime#" />
			<cfinvokeargument name="Title" value="#form.Title#" />
			<cfinvokeargument name="Location" value="#form.Location#" />
			<cfinvokeargument name="ExternalURL" value="#form.ExternalURL#" />
			<cfinvokeargument name="ContactName" value="#form.ContactName#" />
			<cfinvokeargument name="ContactEmail" value="#form.ContactEmail#" />
			<cfinvokeargument name="ContactPhone" value="#form.ContactPhone#" />
			<cfinvokeargument name="Teaser" value="#form.Teaser#" />
			<cfinvokeargument name="Description" value="#form.Description#" />
		</cfinvoke>
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=addRecord&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfsilent>
		</cfcase>
		
		<cfcase value="updateRecord">
		<cfsilent>
		<cfif Len(Trim(form.NewCategoryName))>
			<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories" method="createRecord" returnvariable="returnedCreateCategory">
				<cfinvokeargument name="CategoryName" value="#form.NewCategoryName#" />
			</cfinvoke>
			<cfset form.CategoryID = returnedCreateCategory.NewCategoryID />
		</cfif>
		<cfif NOT Len(Trim(form.EndDate))>
			<cfset form.EndDate = form.StartDate />
		</cfif>
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendar" method="updateRecord" returnvariable="returnMessage">
			<cfinvokeargument name="EventID" value="#form.EventID#" />
			<cfinvokeargument name="CategoryID" value="#form.CategoryID#" />
			<cfinvokeargument name="IsFeatured" value="#form.IsFeatured#" />
			<cfinvokeargument name="IsPublished" value="#form.IsPublished#" />
			<cfinvokeargument name="StartDate" value="#form.StartDate#" />
			<cfinvokeargument name="EndDate" value="#form.EndDate#" />
			<cfinvokeargument name="StartTime" value="#form.StartTime#" />
			<cfinvokeargument name="EndTime" value="#form.EndTime#" />
			<cfinvokeargument name="Title" value="#form.Title#" />
			<cfinvokeargument name="Location" value="#form.Location#" />
			<cfinvokeargument name="ExternalURL" value="#form.ExternalURL#" />
			<cfinvokeargument name="ContactName" value="#form.ContactName#" />
			<cfinvokeargument name="ContactEmail" value="#form.ContactEmail#" />
			<cfinvokeargument name="ContactPhone" value="#form.ContactPhone#" />
			<cfinvokeargument name="Teaser" value="#form.Teaser#" />
			<cfinvokeargument name="Description" value="#form.Description#" />
		</cfinvoke>
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=editRecord&EventID=#form.EventID#&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfsilent>
		</cfcase>
		
		<cfcase value="deleteRecord">
		<cfsilent>
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendar"
					method="deleteRecord"
					returnvariable="returnMessage" EventID="#url.EventID#" />
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=addRecord&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfsilent>
		</cfcase>
		
		<cfcase value="addCategory">
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="getMultipleRecords"
					returnvariable="returnedCategories" />
		<cfscript>
			category = StructNew();
				category.CategoryID = 0;
				category.CategoryName = "";
				category.CategoryBGColor = "";
				category.CategoryTextColor = "";
		</cfscript>
		<cfinclude template="categories.cfm" />
		</cfcase>
		<cfcase value="editCategory">
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="getMultipleRecords"
					returnvariable="returnedCategories" />
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="getSingleRecord"
					CategoryID = "#url.CategoryID#"
					returnvariable="returnedCategory" />
		<cfscript>
			category = StructNew();
				category.CategoryID = returnedCategory.CategoryID;
				category.CategoryName = returnedCategory.CategoryName;
				category.CategoryBGColor = returnedCategory.CategoryBGColor;
				category.CategoryTextColor = returnedCategory.CategoryTextColor;
		</cfscript>
		<cfinclude template="categories.cfm" />
		</cfcase>
		
		<cfcase value="createCategory">
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
				method="createRecord"
				CategoryName = "#form.CategoryName#"
				CategoryBGColor="#form.CategoryBGColor#"
				CategoryTextColor="#form.CategoryTextColor#" />
				
		<cfset returnMessage = "Category was added." />
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=addCategory&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfcase>
		
		<cfcase value="updateCategory">
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="updateRecord"
					CategoryID = "#form.CategoryID#"
					CategoryName = "#form.CategoryName#"
					CategoryBGColor="#form.CategoryBGColor#"
					CategoryTextColor="#form.CategoryTextColor#" />
					
		<cfset returnMessage = "Category was updated." />
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=addCategory&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfcase>
		
		<cfcase value="deleteCategory">
		<cfinvoke component="#application.KConfig.getCFCPath()#kalendarCategories"
					method="deleteRecord"
					CategoryID = "#url.CategoryID#"
					returnvariable="returnMessage" />
					
		<cflocation url="#cgi.SCRIPT_NAME#?appAction=addCategory&returnMessage=#URLEncodedFormat(returnMessage)#" addtoken="false" />
		</cfcase>
		
		<cfcase value="displayImportForms,displayImportData" delimiters=",">
		<cfinclude template="importer.cfm" />
		</cfcase>
		
		<cfcase value="importData">
			<cfloop index="x" from="1" to="#arraylen(session.results)#">
			<cfif StructKeyExists(form, x)>
			<cfinvoke component="#application.KConfig.getCFCPath()#kalendar" method="createRecord" returnvariable="returnMessage">
				<cfinvokeargument name="EventID" value="#CreateUUID()#" />
				<cfinvokeargument name="CategoryID" value="#application.KConfig.getDefaultCategoryID()#" />
				<cfinvokeargument name="IsFeatured" value="0" />
				<cfinvokeargument name="IsPublished" value="1" />
				<cfinvokeargument name="StartDate" value="#DateFormat(session.results[x].StartDate, 'm/d/yyyy')#" />
				<cfinvokeargument name="EndDate" value="#DateFormat(session.results[x].EndDate, 'm/d/yyyy')#" />
				<cfinvokeargument name="StartTime" value="#TimeFormat(session.results[x].StartTime, 'h:mm tt')#" />
				<cfinvokeargument name="EndTime" value="#TimeFormat(session.results[x].EndTime, 'h:mm tt')#" />
				<cfinvokeargument name="Title" value="#session.results[x].Title#" />
				<cfinvokeargument name="Location" value="" />
				<cfinvokeargument name="ExternalURL" value="" />
				<cfinvokeargument name="ContactName" value="" />
				<cfinvokeargument name="ContactEmail" value="" />
				<cfinvokeargument name="ContactPhone" value="" />
				<cfinvokeargument name="Teaser" value="" />
				<cfinvokeargument name="Description" value="#session.results[x].Description#" />
			</cfinvoke>
			</cfif>
			</cfloop>
			<cfset StructDelete(session, "results") />
			Import Complete. It is recommended that you review your imported items to verify that they match the format you expect.
		</cfcase>
	</cfswitch>
	</div>
</div>
</body>
</html>